﻿using System;
using System.Data;
using System.Windows.Forms;

using DevExpress.XtraReports.UI;

using System.IO;
using System.Security.Cryptography;

using DrugsShopManagement.DBCLASS;

namespace DrugsShopManagement
{
    public partial class FrmDrugsBuyDetail : DevExpress.XtraEditors.XtraForm
    {
        public FrmDrugsBuyDetail()
        {
            InitializeComponent();
        }

        Operator op = new Operator();

        //采购单号
        string drugsBuyCode=null; 

        private void FrmDrugsBuyDetail_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Dispose();
        }

        private void FrmDrugsBuyDetail_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“drugsBuy.drugsBuy”中。您可以根据需要移动或删除它。
            this.drugsBuyTableAdapter.Fill(this.drugsBuy.drugsBuy);
            // TODO: 这行代码将数据加载到表“drugsBuy.drugsBuy”中。您可以根据需要移动或删除它。
            this.drugsBuyTableAdapter.Fill(this.drugsBuy.drugsBuy);
            
            // TODO: 这行代码将数据加载到表“drugsBuy.drugsBuy”中。您可以根据需要移动或删除它。
            this.drugsBuyTableAdapter.Fill(this.drugsBuy.drugsBuy);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                XtraReport report = new XtraReport();
                string path = System.IO.Directory.GetCurrentDirectory();
                report.LoadLayout(path + "..\\..\\..\\Reports\\采购单报表.repx");
                ReportPrintTool printTool = new ReportPrintTool(report);
                //DataTable dt = new DataTable();
                DataSet ds = new DataSet();
                //string sql = "select user_id 编号,user_no 用户工号, user_name 用户姓名, user_power 用户权限, user_descripe 用户描述, user_sort 序号 from users order by user_sort";
                //dt = op.getDataTable(sql, "users");
                string sql = "select *,getdate() from drugsBuy where drugsBuyCode=" + drugsBuyCode; ;
                ds = op.getDataSet(sql);
                //report.DataSource = dt;
                report.DataSource = ds;
                //printTool.ShowPreview();
                //printTool.ShowRibbonPreview(UserLookAndFeel.Default);
                printTool.ShowRibbonPreview();
            }
            catch (Exception ex)
            {
                MessageBox.Show("无法打开报表，详细信息：" + ex.ToString());
            }
        }

        private void dGVDrugsBuyDetail_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataTable dt_1 = new DataTable();
            dt_1 = op.getDataTable("select drugsBuyCode from drugsBuy where drugsBuyId='" + this.dGVDrugsBuyDetail.CurrentRow.Cells[0].Value.ToString() + "'", "drugsBuy");
            drugsBuyCode = dt_1.Rows[0]["drugsBuyCode"].ToString();
            this.label1.Text = "该药品采购单号为：" + drugsBuyCode;
            this.label1.Visible = true;
            this.button1.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                XtraReport report = new XtraReport();
                string path = System.IO.Directory.GetCurrentDirectory();
                report.LoadLayout(path + "..\\..\\..\\Reports\\采购单报表.repx");
                ReportPrintTool printTool = new ReportPrintTool(report);
                //DataTable dt = new DataTable();
                DataSet ds = new DataSet();
                //string sql = "select user_id 编号,user_no 用户工号, user_name 用户姓名, user_power 用户权限, user_descripe 用户描述, user_sort 序号 from users order by user_sort";
                //dt = op.getDataTable(sql, "users");
                string sql = "select *,getdate() from drugsBuy";
                ds = op.getDataSet(sql);
                //report.DataSource = dt;
                report.DataSource = ds;
                //printTool.ShowPreview();
                //printTool.ShowRibbonPreview(UserLookAndFeel.Default);
                printTool.ShowRibbonPreview();
            }
            catch (Exception ex)
            {
                MessageBox.Show("无法打开报表，详细信息：" + ex.ToString());
            }
        }
    }
}